/**
 * // Definition for a Node.
 * function Node(val,children) {
 *    this.val = val;
 *    this.children = children;
 * };
 */

/**
 * @param {Node|null} root
 * @return {number[][]}
 */
var levelOrder = function(root) {
    if(!root) return []

    let res = []
    let queue = [root]

    while(queue.length){
        let length = queue.length
        let currentList = []
        for (let index = 0; index < length; index++) {
            let current = queue.shift()
            currentList.push(current.val)
            queue = [...queue,...current.children]
        }
        res.push(currentList)
    }
    return res
};